package com.example.myapplication6;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private EditText etName;
    private TextView tvResult;
    final static String TAG="My Activity A";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.i(TAG,"on Create");

        etName=findViewById(R.id.etName);
        tvResult=findViewById(R.id.jieguo);

        findViewById(R.id.btnin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(TextUtils.isEmpty(etName.getText().toString())){
                    Toast.makeText(MainActivity.this,"输入姓名不能为空",
                            Toast.LENGTH_LONG).show();
                    return;
                }
                Intent myIntent=new Intent(MainActivity.this,SecondActively.class);
                myIntent.putExtra("name",etName.getText().toString().trim());
                //  startActivity(myIntent);
                startActivityForResult(myIntent,1000);
            }
        });

        findViewById(R.id.btnout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==1000 && resultCode==1001){
            String result=data.getStringExtra("result");
            tvResult.setText("评估结果："+ result);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG,"on Start");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG,"on Resume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG,"on Pause");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG,"on Restart");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i(TAG,"on Stop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG,"on Destroy");
    }
}
